package com.mytaobao.main.firsttab.func.headline;

/**
 * Created by hp on 2017/3/31.
 */

import android.widget.TextView;

import com.mytaobao.R;
import com.mytaobao.main.BaseSimplePagerAdapterFragment;

import static com.mytaobao.main.firsttab.func.headline.HeadlineAdapter.itemHeadLine;

/**
 * A placeholder fragment containing a simple view.，多个Fragment可用一个类表示的简单情况
 */
public class HeadlineSimplePagerAdapterFragment extends BaseSimplePagerAdapterFragment {

    @Override
    public void _onCreateView() {
        sectionNumber = toRealPosition(sectionNumber);
        ((TextView)rootView.findViewById(R.id.tv_headline_11)).setText(itemHeadLine.getItems().get(sectionNumber).get(0).get(0));
        ((TextView)rootView.findViewById(R.id.tv_headline_12)).setText(itemHeadLine.getItems().get(sectionNumber).get(0).get(1));
        ((TextView)rootView.findViewById(R.id.tv_headline_21)).setText(itemHeadLine.getItems().get(sectionNumber).get(1).get(0));
        ((TextView)rootView.findViewById(R.id.tv_headline_22)).setText(itemHeadLine.getItems().get(sectionNumber).get(1).get(1));
    }
    @Override
    protected int getAdapterLayoutView() {
        return R.layout.adapter_headline;
    }

    public static BaseSimplePagerAdapterFragment newInstance(int sectionNumber) {
        return BaseSimplePagerAdapterFragment.createNewInstance(sectionNumber, new HeadlineSimplePagerAdapterFragment());
    }

    public int toRealPosition(int position) {
        int realPosition;
        realPosition = (position - 1) % itemHeadLine.getItems().size();
        if (realPosition < 0)
            realPosition += itemHeadLine.getItems().size();
        return realPosition;
    }
}
